<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="mybean.data.DataByPage" %>
<%@ page import="javax.sql.rowset.*" %>
<jsp:useBean id="loginBean" class="mybean.data.login" scope="session"/>
<jsp:useBean id="dataBean" class="mybean.data.DataByPage" scope="session"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>单车使用记录</title>
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link rel="stylesheet" type="text/css" href="css/common.css">
	<link rel="stylesheet" type="text/css" href="css/index-2.css">
	<link rel="stylesheet" type="text/css" href="css/index-1.css">
</head>
<body>
	<%@ include file="Ahead.txt" %>
	<div class="Admin-content">			
		<center>
		<!-- 分页显示查询结果 -->
		<jsp:setProperty name="dataBean" property="pageSize" param="pageSize"/><!-- 设置页大小和目前的页 -->
		<jsp:setProperty name="dataBean" property="currentPage" param="currentPage"/>
		<%
			request.setCharacterEncoding("utf-8");
			response.setContentType("utf-8");
			CachedRowSet rowset=dataBean.getRowSet();
			if(rowset== null){
				out.print("<h2>没有查询到相关信息</h2>");
				return;
			}
			else{
				String button="";
				rowset.last();
				int totalRecord=rowset.getRow();
				if(totalRecord==0){
					out.print("<h2>没有查询到相关信息</h2>");
					return ;
				}
				%>
		<h3>当前显示的是单车使用记录信息</h3>
		<table>
			<tr style="background-color: #004b97;color: white">
				<th width=100 height=40>单车编号</th>
				<th width=100 height=40>用户名</th>
				<th width=200 height=40>使用日期</th>
			</tr>			
				<% 
				out.print("全部记录数"+totalRecord);//全部记录数
				int pageSize = dataBean.getPageSize();//每页显示的记录数
				int totalPages=dataBean.getTotalPages();
				if(totalRecord % pageSize==0)  totalPages=totalRecord/pageSize;//总页数
				else	totalPages=totalRecord/pageSize+1;
				dataBean.setPageSize(pageSize);
				dataBean.setTotalPages(totalPages);
				if(totalPages>=1){
					if(dataBean.getCurrentPage()<1)	dataBean.setCurrentPage(dataBean.getTotalPages());
					if(dataBean.getCurrentPage()>dataBean.getTotalPages())
						dataBean.setCurrentPage(1);
					int index = (dataBean.getCurrentPage()-1)*pageSize+1;
					rowset.absolute(index);//查询位置移动到currentPage页起始位置
					boolean boo=true;
					for(int i=1;i<=pageSize&&boo;i++){
						String id = rowset.getString("B_id");
						String name = rowset.getString("username");
						String date= rowset.getString("usertime");
			%>
			<tr style="background-color: #c0c0c0;">
				<td height=50><center><%=id %></center></td>
				<td height=50><center><%=name %><center></td>
				<td height=50><center><%=date %></center></td>
			</tr>
				<%		boo=rowset.next();
					}}}
			%>			
		</table>
		<%@ include file="bypage.txt" %>		
		</center>				
    </div>	
	<!--页面底部-->
	<!--所以的页面底部都一样，用一个文本文件存储，所有JSP文件使用嵌入-->
	<%@ include file="footer.txt" %>
</body>
</html>